// 解构断言
function test() {
  let a = 'coderzrf'
  let b = (x: number, y: number): number => x + y
  // return [a, b] as [typeof a, typeof b]
  return [a, b] as const // 等同于上行代码 放到外面无效
}

// let [n, m] = test() as [string, Function]
// console.log((m as Function)(1, 2))
let [n, m] = test()
console.log(m(1, 2));
{
  // 非空断言
  let el: HTMLDivElement = document.querySelector('.main') as HTMLDivElement
  // let el: HTMLDivElement = document.querySelector('.main')! // 感叹号去空
  el.innerHTML = '555'

  // class构造函数强制断言
  class Test {
    el: HTMLDivElement
    constructor(el: HTMLDivElement) {
      this.el = el
    }
    html() {
      console.log(this.el.innerHTML)
    }
  }
  let ele = document.querySelector('.main') as HTMLDivElement
  new Test(ele).html()

  // DOM事件处理
  const btn = document.querySelector('.btn') as HTMLButtonElement
  btn.addEventListener('click', (e: Event) => {
    e.preventDefault()
    const body = document.querySelector('body')!
    body.insertAdjacentHTML('beforeend', '<h1>Helllo</h1>')
  })
}




